<?php

namespace Addons\OaSystem\Controller;

class OaApplyTypeController extends OaBaseController
{
    protected $model;

    function _initialize()
    {
        $this->model = $this->getModel('oa_apply_type');
        parent::_initialize();

        $res ['title'] = '流程管理';
        $res ['url'] = addons_url ( 'OaSystem://OaProcessFlow/lists' ,array('mdm'=>I('mdm')));
        $res ['class'] = $controller == 'OaProcessFlow' ? 'current' : '';
        $nav [] = $res;
        $this->assign ( 'nav', $nav );

        $res ['title'] = '流程列表';
        $sub_nav[] = $res;
        $res ['title'] = '流程类型';
        $res ['url'] = addons_url ( 'OaSystem://OaApplyType/lists' ,array('mdm'=>I('mdm')));
        $res ['class'] = $controller == 'OaApplyType' ? 'current' : '';
        $sub_nav[] = $res;
        $this->assign ( 'sub_nav', $sub_nav );

    }
    function lists(){
        $list_data = $this->_get_model_list( $this->model );
        $this -> assign($list_data);
        $this->display();
    }

    function add(){
        if(IS_POST) {
            $data['appid'] = $this->appId;
            $data['name'] = $_POST['name'];
            $data['remark'] = $_POST['remark'];
            $data['sn'] = $_POST['sn'];

            if(db_find('oa_apply_type', array('name'=>$data['name']))) {
                $this->error('该审批类型名称已经存在, 请重新输入！');
                return false;
            }

            M('oa_apply_type')->add($data);

            $this->success ( '创建' . $model ['title'] . '成功！', U ( 'lists?model=' . $model ['name'], $this->get_param ));
        } else {
            $this->display('add');
        }
    }
}